package com.F06.business;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.read.biff.BiffException;
import jxl.write.Border;
import jxl.write.BorderLineStyle;
import jxl.write.Formula;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import com.F06.action.F060103Action;
import com.F06.actionForm.F060103ActionForm;
import com.F06.dao.F060103DAO;
import com.action.BaseAction;
import com.util.ExcelExport;

public class F060103Business {

	public static void writeExcel(String modlePath, String outName,F060103DAO dao,F060103ActionForm actionForm) {
		/** 记录操作日志 */
		Logger log = Logger.getLogger(F060103Business.class);
		String time = actionForm.getSignaure_date_year()+"-"+actionForm.getSignaure_date_month()+"-1";
		log.info("time = "+time);
		WritableWorkbook wwb = null;
		Workbook workbook = null;
		List sheet0 = new ArrayList();
		List sheet1 = new ArrayList();
		List sheet2 = new ArrayList();
		Map sheetmap = new HashMap(); 
		Map sheetmap1 = new HashMap(); 
		Map sheetmap2 = new HashMap(); 
		String all = "all";// 单元格类型的参数
		String none = "none";// 单元格类型的参数
		String center = "center";// 单元格类型的参数
		try {
			try {
				// 根据模板去创建新的工作簿
				InputStream ins = new FileInputStream(modlePath);
				workbook = Workbook.getWorkbook(ins);
				File outFile = new File(outName);
				wwb = Workbook.createWorkbook(outFile, workbook);
			} catch (BiffException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (wwb != null) {
				try {
					// 得到工作表第一页
					WritableSheet wsheet0 = wwb.getSheet(0);
					if (wsheet0 != null) {
						log.info(" wsheet0 " + wsheet0.getColumns());
						sheet0=dao.sheet0(time);
						int hh =1;
						if(sheet0!=null&&sheet0.size()>0){
							int sheet0hh = 3;
							for (int i = 0; i<sheet0.size(); i++) {
								sheetmap = (Map) sheet0.get(i);
								wsheet0.addCell(new Label(0, sheet0hh, String.valueOf(hh),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Label(1, sheet0hh, sheetmap.get("销售员").toString(),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Label(2, sheet0hh, sheetmap.get("地区").toString(),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(3, sheet0hh, Double.parseDouble(sheetmap.get("未入库合同金额").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(4, sheet0hh, Double.parseDouble(sheetmap.get("month1").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(5, sheet0hh, Double.parseDouble(sheetmap.get("month2").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(6, sheet0hh, Double.parseDouble(sheetmap.get("month3").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(7, sheet0hh, Double.parseDouble(sheetmap.get("month4").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(8, sheet0hh, Double.parseDouble(sheetmap.get("month5").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(9, sheet0hh, Double.parseDouble(sheetmap.get("month6").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(10, sheet0hh, Double.parseDouble(sheetmap.get("month7").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(11, sheet0hh, Double.parseDouble(sheetmap.get("month8").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(12, sheet0hh, Double.parseDouble(sheetmap.get("month9").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(13, sheet0hh, Double.parseDouble(sheetmap.get("month10").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(14, sheet0hh, Double.parseDouble(sheetmap.get("month11").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Number(15, sheet0hh, Double.parseDouble(sheetmap.get("month12").toString()),ExcelExport.getStyle(8,"8")));
								wsheet0.addCell(new Formula(16,sheet0hh,"D"+(sheet0hh+1)+"+E"+(sheet0hh+1)+"+F"+(sheet0hh+1)+"+G"+(sheet0hh+1)+"+H"+(sheet0hh+1)+"+I"+(sheet0hh+1)+"+J"+(sheet0hh+1)+"+K"+(sheet0hh+1)+"+L"+(sheet0hh+1)+"+M"+(sheet0hh+1)+"+N"+(sheet0hh+1)+"+O"+(sheet0hh+1),ExcelExport.getStyle(8,"9")));
								sheet0hh = sheet0hh + 1;
								hh++;
							}
							wsheet0.mergeCells(0, sheet0hh, 2, sheet0hh);
							wsheet0.addCell(new Label(0, sheet0hh, "合计",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(3, sheet0hh, "SUM(D4:D"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(4, sheet0hh, "SUM(E4:E"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(5, sheet0hh, "SUM(F4:F"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(6, sheet0hh, "SUM(G4:G"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(7, sheet0hh, "SUM(H4:H"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(8, sheet0hh, "SUM(I4:I"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(9, sheet0hh, "SUM(J4:J"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(10, sheet0hh, "SUM(K4:K"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(11, sheet0hh, "SUM(L4:L"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(12, sheet0hh, "SUM(M4:M"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(13, sheet0hh, "SUM(N4:N"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(14, sheet0hh, "SUM(O4:O"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(15, sheet0hh, "SUM(P4:P"+sheet0hh+")",ExcelExport.getStyle(8,"9")));
							wsheet0.addCell(new Formula(16,sheet0hh,"SUM(Q4:Q"+sheet0hh+")",ExcelExport.getStyle(8,"9")));

							log.info(" wsheet0 " + wsheet0.getColumns());
						}else {
							wsheet0.addCell(new Label(0, 8, "数据查询结果为空"));
						}
					} 
					// 得到工作表第二页
					WritableSheet wsheet1 = wwb.getSheet(1);
					if (wsheet1 != null) {
						log.info(" wsheet1 " + wsheet1.getColumns());
						sheet1=dao.sheet1(time);
						if(sheet1!=null&&sheet1.size()>0){
							int sheet1hh = 3;
							int hh =1;
							for (int i = 0; i < sheet1.size(); i++) {
								sheetmap1 = (Map) sheet1.get(i);
								wsheet1.addCell(new Label(0, sheet1hh, String.valueOf(hh),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Label(1, sheet1hh, sheetmap1.get("product_type").toString(),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(2, sheet1hh, Double.parseDouble(sheetmap1.get("quantity_lastyear").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(3, sheet1hh, Double.parseDouble(sheetmap1.get("total_price_lastyear").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(4, sheet1hh, Double.parseDouble(sheetmap1.get("total_price1").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(5, sheet1hh, Double.parseDouble(sheetmap1.get("quantity1").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(6, sheet1hh, Double.parseDouble(sheetmap1.get("total_price2").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(7, sheet1hh, Double.parseDouble(sheetmap1.get("quantity2").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(8, sheet1hh, Double.parseDouble(sheetmap1.get("total_price3").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(9, sheet1hh, Double.parseDouble(sheetmap1.get("quantity3").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(10, sheet1hh, Double.parseDouble(sheetmap1.get("total_price4").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(11, sheet1hh, Double.parseDouble(sheetmap1.get("quantity4").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(12, sheet1hh, Double.parseDouble(sheetmap1.get("total_price5").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(13, sheet1hh, Double.parseDouble(sheetmap1.get("quantity5").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(14, sheet1hh, Double.parseDouble(sheetmap1.get("total_price6").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(15, sheet1hh, Double.parseDouble(sheetmap1.get("quantity6").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(16, sheet1hh, Double.parseDouble(sheetmap1.get("total_price7").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(17, sheet1hh, Double.parseDouble(sheetmap1.get("quantity7").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(18, sheet1hh, Double.parseDouble(sheetmap1.get("total_price8").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(19, sheet1hh, Double.parseDouble(sheetmap1.get("quantity8").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(20, sheet1hh, Double.parseDouble(sheetmap1.get("total_price9").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(21, sheet1hh, Double.parseDouble(sheetmap1.get("quantity9").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(22, sheet1hh, Double.parseDouble(sheetmap1.get("total_price10").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(23, sheet1hh, Double.parseDouble(sheetmap1.get("quantity10").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(24, sheet1hh, Double.parseDouble(sheetmap1.get("total_price11").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(25, sheet1hh, Double.parseDouble(sheetmap1.get("quantity11").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(26, sheet1hh, Double.parseDouble(sheetmap1.get("total_price12").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Number(27, sheet1hh, Double.parseDouble(sheetmap1.get("quantity12").toString()),ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Formula(28, sheet1hh,"C"+(sheet1hh+1)+"+E"+(sheet1hh+1)+"+G"+(sheet1hh+1)+"+I"+(sheet1hh+1)+"+K"+(sheet1hh+1)+"+M"+(sheet1hh+1)+"+O"+(sheet1hh+1)+"+Q"+(sheet1hh+1)+"+S"+(sheet1hh+1)+"+U"+(sheet1hh+1)+"+W"+(sheet1hh+1)+"+Y"+(sheet1hh+1)+"+AA"+(sheet1hh+1) ,ExcelExport.getStyle(8,"8")));
								wsheet1.addCell(new Formula(29, sheet1hh,"D"+(sheet1hh+1)+"+F"+(sheet1hh+1)+"+H"+(sheet1hh+1)+"+J"+(sheet1hh+1)+"+L"+(sheet1hh+1)+"+N"+(sheet1hh+1)+"+P"+(sheet1hh+1)+"+R"+(sheet1hh+1)+"+T"+(sheet1hh+1)+"+V"+(sheet1hh+1)+"+X"+(sheet1hh+1)+"+Z"+(sheet1hh+1)+"+AB"+(sheet1hh+1) ,ExcelExport.getStyle(8,"8")));
								sheet1hh = sheet1hh + 1;
								hh++;
							}
							wsheet1.mergeCells(0, sheet1hh, 1, sheet1hh);
							wsheet1.addCell(new Label(0, sheet1hh,"合计",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(1, sheet1hh,"SUM(B4:B"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(2, sheet1hh,"SUM(C4:C"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(3, sheet1hh,"SUM(D4:D"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(4, sheet1hh,"SUM(E4:E"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(5, sheet1hh,"SUM(F4:F"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(6, sheet1hh,"SUM(G4:G"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(7, sheet1hh,"SUM(H4:H"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(8, sheet1hh,"SUM(I4:I"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(9, sheet1hh,"SUM(J4:J"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(10, sheet1hh,"SUM(K4:K"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(11, sheet1hh,"SUM(L4:L"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(12, sheet1hh,"SUM(M4:M"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(13, sheet1hh,"SUM(N4:N"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(14,sheet1hh,"SUM(O4:O"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(15,sheet1hh,"SUM(P4:P"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(16,sheet1hh,"SUM(Q4:Q"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(17,sheet1hh,"SUM(R4:R"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(18,sheet1hh,"SUM(S4:S"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(19,sheet1hh,"SUM(T4:T"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(20,sheet1hh,"SUM(U4:U"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(21,sheet1hh,"SUM(V4:V"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(22,sheet1hh,"SUM(W4:W"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(23,sheet1hh,"SUM(X4:X"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(24,sheet1hh,"SUM(Y4:Y"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(25,sheet1hh,"SUM(Z4:Z"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(26,sheet1hh,"SUM(AA4:AA"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(27,sheet1hh,"SUM(AB4:AB"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(28,sheet1hh,"SUM(AC4:AC"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							wsheet1.addCell(new Formula(29,sheet1hh,"SUM(AD4:AD"+sheet1hh+")",ExcelExport.getStyle(8,"9")));
							log.info(" wsheet1 " + wsheet1.getColumns());
						}
						else {
								wsheet1.addCell(new Label(0, 8, "数据查询结果为空"));
						}
					}

					// 得到工作表第三页
					WritableSheet wsheet2 = wwb.getSheet(2);
					if (wsheet2 != null) {
						log.info(" wsheet2 " + wsheet2.getColumns());
						sheet2=dao.sheet2(time);
						if(sheet2!=null&sheet2.size()>0){
						int sheet2hh = 3;
						for (int i = 0; i < sheet2.size(); i++) {
							sheetmap2 = (Map) sheet2.get(i);
							wsheet2.addCell(new Label(0, sheet2hh, sheetmap2.get("销售员").toString(),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Label(1, sheet2hh, sheetmap2.get("地区").toString(),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(2, sheet2hh, Double.parseDouble(sheetmap2.get("month1").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(3, sheet2hh, Double.parseDouble(sheetmap2.get("month2").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(4, sheet2hh, Double.parseDouble(sheetmap2.get("month3").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(5, sheet2hh, Double.parseDouble(sheetmap2.get("month4").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(6, sheet2hh, Double.parseDouble(sheetmap2.get("month5").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(7, sheet2hh, Double.parseDouble(sheetmap2.get("month6").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(8, sheet2hh, Double.parseDouble(sheetmap2.get("month7").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(9, sheet2hh, Double.parseDouble(sheetmap2.get("month8").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(10, sheet2hh, Double.parseDouble(sheetmap2.get("month9").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(11, sheet2hh, Double.parseDouble(sheetmap2.get("month10").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(12, sheet2hh, Double.parseDouble(sheetmap2.get("month11").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Number(13, sheet2hh, Double.parseDouble(sheetmap2.get("month12").toString()),ExcelExport.getStyle(8,"8")));
							wsheet2.addCell(new Formula(14,sheet2hh,"C"+(sheet2hh+1)+"+D"+(sheet2hh+1)+"+E"+(sheet2hh+1)+"+F"+(sheet2hh+1)+"+G"+(sheet2hh+1)+"+H"+(sheet2hh+1)+"+I"+(sheet2hh+1)+"+J"+(sheet2hh+1)+"+K"+(sheet2hh+1)+"+L"+(sheet2hh+1)+"+M"+(sheet2hh+1)+"+N"+(sheet2hh+1),ExcelExport.getStyle(8,"9")));
							sheet2hh++;
						}
						wsheet2.mergeCells(0, sheet2hh, 1, sheet2hh);
						wsheet2.addCell(new Label(0, sheet2hh, "合计",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(2, sheet2hh, "SUM(C4:C"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(3, sheet2hh, "SUM(D4:D"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(4, sheet2hh, "SUM(E4:E"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(5, sheet2hh, "SUM(F4:F"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(6, sheet2hh, "SUM(G4:G"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(7, sheet2hh, "SUM(H4:H"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(8, sheet2hh, "SUM(I4:I"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(9, sheet2hh, "SUM(J4:J"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(10, sheet2hh, "SUM(K4:K"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(11, sheet2hh, "SUM(L4:L"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(12, sheet2hh, "SUM(M4:M"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(13, sheet2hh, "SUM(N4:N"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						wsheet2.addCell(new Formula(14, sheet2hh, "SUM(O4:O"+sheet2hh+")",ExcelExport.getStyle(8,"9")));
						log.info(" wsheet2 " + wsheet2.getColumns());
		                   
						}else {
							wsheet2.addCell(new Label(0, 8, "数据查询结果为空"));
						}
					} 
					wwb.write();
					actionForm.setErrorFlag("7");
				} catch (RowsExceededException e) {
					actionForm.setErrorFlag("6");
					e.printStackTrace();
				} catch (WriteException e) {
					actionForm.setErrorFlag("6");
					e.printStackTrace();
				}
			}
		} catch (Exception e) {
			System.out.print("写入Excel出错");
			e.printStackTrace();
		} finally {
			try {
				workbook.close();
				wwb.close();
			} catch (WriteException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
